<?php
	include("includes/secure.php");
	include("includes/config.php");
	include("includes/class/adviser.class.php");
	
	$adviser = new Adviser(); 	
	
	$msg_info = $msg_alert = $msg_error = false;
	$_SESSION['msg_cool'] = '';
	$show_msg = 0;
			
	if(isset($_POST['addAdviser']) && $_POST['addAdviser'] == 1){
		$action = $_POST["action"];
		$data->ase_name = trim(mysql_real_escape_string($_POST['ase_name']));
		$data->ase_ced = trim(mysql_real_escape_string($_POST['ase_ced']));
		$data->ase_email  = trim(mysql_real_escape_string($_POST['ase_email']));
		
		if ( $data->id_fk = $adviser->addAdviser($data) ){
			$msg_info = true;
			$_SESSION["msg_cool"] .= 'El asesor fue adicionado satisfactoriamente!!.<br />';
			
			$countTel_number = count ( $_POST['tel_number'] );
			$i = 0;
			while ( $i < $countTel_number ){
				$data->tel_number = $_POST['tel_number'][$i];
				$data->tel_ext = $_POST['tel_ext'][$i];
				
				if ( ! $adviser->addTelephone($data) ){
					$msg_alert = true;
					$_SESSION["msg_cool"] .= 'Error adicionando telefonos asesor!!.<br />';
				}
					
				$i ++;
			}
			
			if ( $action == 1 )
				echo "<script> window.location.href='listAdviser.php?show_msg=3'</script>";
			elseif ( $action == 2 )
				echo "<script> window.location.href='addAdviser.php?hdv_code=".$data->id_fk."'</script>";
				
		}
		else{
			$msg_info = true;
			$_SESSION["msg_cool"] .= 'No pudo ser adicionado el Asesor!.<br />';
			echo "<script> window.location.href='listAdviser.php?show_msg=1'</script>";
		}
	}
	
	if ( $msg_error )
		$show_msg = 1;
	elseif ( $msg_alert )
		$show_msg = 2;
	elseif ( $msg_info )
		$show_msg = 3;
?>